
function OpenDivDialog(sUrl,sArgs,sDialogWidth,sDialogHeight,sResizable,sCNTitle,sENTitle)
{
	var divWinObj = createDivWin(sDialogWidth,sDialogHeight);
	if(sUrl.indexOf("?") > -1)
		sUrl += "&";
	else
		sUrl += "?";
		
	divWinObj.location.href = sUrl + sArgs;
	moveDiv_init();
}
function buttonClose(isRefesh){
	//parent.PopupFormDiv.style.display = 'none';
	//parent.PopupFormFrame.location.href = 'about:blank';
	if(isRefesh==null) isRefesh = false;
	PopupFormDiv.style.display = 'none';
	PopupFormFrame.location.href = 'about:blank';
	if(isRefesh)
		window.location.reload();
}

function CloseDivDialog(isUpdate){
	var s = CurrentOpenned;
	
	parent.PopupFormDiv.style.display = 'none';
	parent.PopupFormFrame.location.href = 'about:blank';
	if (isUpdate){
		switch (s){
			case 2:
				break;			
		}				
	}
	return isUpdate;			
}

//移动层窗口
function moveDiv_setZIndex(obj, zOrder) {
	obj.zIndex = zOrder
}
function moveDiv_shiftTo(obj, x, y) {
		if ((x>=0)&&(x<window.screen.width-50)){
		obj.pixelLeft = x;

		}
		if ((y>=0)&&(y<window.screen.height-100)){
		obj.pixelTop = y;		
		}		
	
}
var selectedObj
var offsetX, offsetY

function moveDiv_setSelectedElem(evt) {
	
		var imgObj = window.event.srcElement;
		if (imgObj.id=='dragDiv') {
			
			selectedObj = document.all.PopupFormDiv.style;
			moveDiv_setZIndex(selectedObj,100);
			return;
		}
		selectedObj = null;
		return;
}

function moveDiv_dragIt(evt) {
	if (window.event.srcElement.id=='dragDiv'){
		window.event.srcElement.style.cursor = "move";
	}
	if (selectedObj) {
			moveDiv_shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY));
			return false;
	}
}

function moveDiv_engage(evt) {
	moveDiv_setSelectedElem(evt);
	if (selectedObj) {
			offsetX = window.event.offsetX;
			offsetY = window.event.offsetY;
	}
	return false;
}

function moveDiv_release(evt) {
	if (selectedObj) {
		moveDiv_setZIndex(selectedObj, 0);
		selectedObj = null;
	}
}

function moveDiv_init() {
	document.all.dragDivTd.onmousedown = moveDiv_engage;
	document.all.dragDivTd.onmousemove = moveDiv_dragIt;
	document.all.dragDivTd.onmouseup = moveDiv_release;
}

function createDivWin(sDivWidth,sDivHeight){
	if (typeof(document.all.PopupFormDiv)=='object'){
		document.getElementsByTagName("body").item(0).removeChild(document.all.PopupFormDiv);
	}
	var bodyObj = document.getElementsByTagName("body").item(0);
	var divObj =  document.createElement("div");
	var strHTML;
	bodyObj.appendChild(divObj);
	
	divObj.id						= "PopupFormDiv";
	divObj.name						= "PopupFormDiv";	
	divObj.style.position			= 'absolute';
	divObj.style.border				= '2px outset';
	divObj.style.borderTop			= '2px outset #D5E4F0';
	divObj.style.borderLeft			= '2px outset #D5E4F0';
	divObj.style.borderRight		= '2px outset #D5E4F0';
	divObj.style.borderBottom		= '2px outset #D5E4F0';
	divObj.style.backgroundColor	= '#EEF0F2';
	divObj.style.width				= sDivWidth;
	divObj.style.height				= sDivHeight;
	divObj.style.left				= (bodyObj.clientWidth-parseInt(sDivWidth))/2;
	divObj.style.top				= (bodyObj.clientHeight-parseInt(sDivHeight))/2-15;	
	
	var imgPath = getLibURI() + "default/image/";
	strHTML = '<table width="100%"  border="0" cellspacing="0" cellpadding="0"><tr>';
	strHTML = strHTML + '<td id="dragDivTd"><img id="dragDiv" src="'+imgPath+'head.gif" width="';
	strHTML = strHTML +	(parseInt(sDivWidth)-20)+'" height="20"></td>';
	strHTML = strHTML + '<td width="20"><img src="'+imgPath+'closeIMG1.gif" onmousedown="this.src=\''+imgPath+'closeIMG2.gif\'" onmouseout="this.src=\''+imgPath+'closeIMG1.gif\'" onclick="buttonClose(false);" WIDTH="20" HEIGHT="20"  style="cursor:hand;"></td></tr></table>';
	strHTML = strHTML + '<iframe id="PopupFormFrame" width="'+sDivWidth+'" FRAMEBORDER="0" height="'+sDivHeight+'"></iframe>';
	
	divObj.innerHTML = strHTML;
	return window.PopupFormFrame;
}